package com.dr.java.day04;

import static com.dr.java.day04.Array1.printArrAsStr;

/**
 * Created by rui on 2017/12/29.
 */
public class ReverseArr {
    public static void main(String[] args) {
        int[] arr = {3, 1, 5, 6, 2, 0};
        printArrAsStr(arr);
        printArrAsStr(reverse(arr));
    }

    private static int[] reverse(int[] arr) {
        for (int i = 0; i < arr.length / 2; i++) {
            swap(arr, i, arr.length - 1 - i);
        }
        return arr;
    }

    private static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
